package cate.game.train.fairy.msg;

import cate.common.annotation.OperationSetter;
import cate.common.table.d.GDOperation;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBTrain;
import cate.game.role.Role;
import cate.game.role.bag.hero.Hero;
import easy.java.dev.note.NoteField;
import easy.java.practice.errorcode.EcResult;

@ClientMsg(title = "英雄脱灵器 の 请求")
@OperationSetter(GDOperation.FAIRY_OFF)
public class FairyOffReq implements MsgInput {
    @NoteField(value = "英雄uid")
    public String heroUid;

    @NoteField(value = "要脱掉的部位")
    public byte pos;

    @Override
    public void execute(GameBody game, ClientContext cc) {
        Role role = cc.getRole();
        Hero hero = role.getBag().hero.getItem(heroUid);
        if (hero == null) {
            role.getGame().notice.message(role, "英雄不存在");
            return;
        }
        EcResult r = hero.offFairy(role.toPlayBuildContext(), pos);
        if (!r.ok()) {
            role.getGame().notice.message(role, r.message);
            return;
        }
        cc.sendNow(new FairyOffResp(heroUid, pos));
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBTrain.HERO_FAIRY_OFF_REQ;
    }
}
